package com.wenjie.redHat.controller;


import com.wenjie.redHat.commom.R;
import com.wenjie.redHat.domain.entity.ProductCategoryEntity;
import com.wenjie.redHat.service.ProductCategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/productCategory")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;

    @ApiOperation("保存分类")
    @PostMapping("/save")
    public R save(@RequestBody  ProductCategoryEntity productCategoryEntity){
        ProductCategoryEntity productCategory=productCategoryService.saveProductCategory(productCategoryEntity);
        if (productCategory==null){
            return R.error("添加失败");
        }
        else {
            return R.success(productCategory);
        }


    }
    @ApiOperation("修改分类")
    @PostMapping("/update")
    public R update( @RequestBody ProductCategoryEntity productCategoryEntity){
        return R.success(productCategoryService.updateProductCategory(productCategoryEntity));
    }

    @ApiOperation("获取单个分类信息")
    @GetMapping("/get/{id}")
    public R getByOne(@PathVariable Integer id){
        return R.success(productCategoryService.getById(id));
    }
    @ApiOperation("获取全部分类信息")
    @GetMapping("/getList")
    public R getList(){
        return R.success(productCategoryService.list());
    }
    @ApiOperation("删除分类")
    @PostMapping("/delete/{id}")
    public R deleteId(@PathVariable Integer id){
        return R.success(productCategoryService.removeById(id));

    }
}
